﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Barbar.Colonization.Model.Script.WorldCommands {
  public class CreateUnit : WorldCommand {
    private Coordinate m_Coordinate;
    private IUnitType m_UnitType;
    private Race m_Race;

    public CreateUnit(World world, Coordinate coordinate, IUnitType unitType, Race race) : base(world) {
      m_Coordinate = coordinate;
      m_UnitType = unitType;
      m_Race = race;
    }
    

    public override void Execute() {
      Unit unit = m_UnitType.CreateUnit();
      ((IUnitLocation)m_Race).PlaceNewUnit(unit);
      ((IUnitLocation)InternalWorld[m_Coordinate]).PlaceNewUnit(unit);
      City city = InternalWorld[m_Coordinate].City;
      if (city != null)
        ((IUnitLocation)city).PlaceNewUnit(unit);
    }
  }
}
